package wireless.program.action;


import cm.util.exception.MessageException;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class ProgramChange extends ActionSupport{

	private String type;
	
	private String programpath;
	
	private static final String OPEN = "open";

	private static final String CLOSE = "close";
	
	public String getType() {
		return type;
	}
	public void setType(String type) {
		this.type = type;
	}
	
	public String getProgrampath() {
		return programpath;
	}
	public void setProgrampath(String programpath) {
		this.programpath = programpath;
	}
	public String execute() throws Exception {

		if (type == null || "".equals(type)) {
			throw new MessageException("操作类型不能为空！");
		}

		if (CLOSE.equals(type)) {
			//Runtime.getRuntime().exec ("/root/bin/test.sh");
			ActionContext.getContext().getSession().put("state","close");
			
			return "success";
		}
		if (OPEN.equals(type)) {
			Runtime.getRuntime().exec ("cmd.exe /k start "+programpath);
			ActionContext.getContext().getSession().put("state","open");
			
			return "success";
		}
		return super.execute();
	}
	
}
